home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12867 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: sooner.net!usenet
  2. From: Eddie Bush <edwbush@sooner.net>
  3. Newsgroups: comp.lang.c
  4. Subject: Recursion
  5. Date: Wed, 03 Apr 1996 01:58:26 -0800
  6. Organization: sooner.net news site
  7. Message-ID: <31624BC2.70D2@sooner.net>
  8. NNTP-Posting-Host: p22.sooner.net
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (Win16; I)
  13.  
  14. I am trying to construct a C function that will recursively convert
  15. a string such as "1234" into it's integer equivelant (1234).
  16.  
  17. Here is what I know:
  18. 1)if you subtract the character "0" from any of the other digits "1".."9"
  19.   you will get the integer value of that characer.
  20.     Example:  "1" - "0" is equal to 1
  21.           "2" - "0" is equal to 2
  22.           .
  23.           .
  24.           .
  25.           "9" - "0" is equal to 9
  26. 2)the function should be called with a character pointer:
  27.     Such as:   convert("1234");
  28.   making the prototype look something like:
  29.     int convert(char *p);
  30.  
  31. Does anyone have an idea?  This is sorta stumping me.  I am aware of 
  32. atoi, but I am wanting to write a recursive function that does that -- 
  33. for the fun of it.  It's sort of a little puzzle to help me learn 
  34. recursion.  Any ideas?
  35.  
  36. Thanx in Advance!
  37.